package com.slipper.collect;

import com.slipper.collect.support.*;
import com.slipper.util.Tool;

import java.util.HashMap;
import java.util.Map;

public class DataConvertFactory {
    private static final Map<String, IDataConvert> dataConvertMap = new HashMap<>() {{
        put("默认值", new DefaultDataConvert());
        put("日期格式化", new DateFormatDataConvert());
        put("时间转秒", new DateToSecondDataConvert());
        put("时间转毫秒", new DateToMillsDataConvert());
        put("秒转时间", new SecondToDateDataConvert());
        put("毫秒转时间", new MillsToDateDataConvert());
    }};

    public static Object convert(String type, String param, Object value) {
        if (Tool.isBlank(type)) return value;
        IDataConvert convert = dataConvertMap.get(type);
        if (convert == null) throw new RuntimeException("不支持数据转换类型【" + type + "】");
        return convert.convert(param, value);
    }
}
